/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.myapp.DAO;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import org.apt.Bean.PaymentSeminarEntities;
import org.apt.connectDB.MyConnect;

/**
 *
 * @author Administrator
 */
public class PaymentSeminarDao {

    public static boolean InsertPaymentSeminar(PaymentSeminarEntities paymentSeminar) {
        boolean resuilt = false;
        Connection con = null;
        Statement st = null;
        ResultSet rs = null;
        try {
            if (paymentSeminar != null) {
                String sql = "insert into PaymentSeminar values('" + paymentSeminar.getUser() + "'," + paymentSeminar.getSeminarID() + "," + paymentSeminar.getGroupPaymentID() + ",'" + paymentSeminar.isStatusPayment() + "','" + paymentSeminar.isStatus() + "','" + paymentSeminar.getDescription() + "')";
                con = MyConnect.getConnection();
                st = con.createStatement();
                int number = st.executeUpdate(sql);
                if (number > 0) {
                    resuilt = true;
                } else {
                    resuilt = true;
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println(e.getMessage());
        } finally {
            MyConnect.closeConntion(con, st, rs);
        }
        return resuilt;
    }

    public static PaymentSeminarEntities getPaymentSeminarByUserAndID(String user, int seminarID) {
        PaymentSeminarEntities seminarPayment = new PaymentSeminarEntities();
        Connection con = null;
        Statement st = null;
        ResultSet rs = null;
        String sql = "Select * from PaymentSeminar where [User] ='" + user + "' and SeminarID=" + seminarID + " ";
        try {
            con = MyConnect.getConnection();
            st = con.createStatement();
            rs = st.executeQuery(sql);
            while (rs.next()) {
                seminarPayment.setID(rs.getInt("ID"));
                seminarPayment.setUser(rs.getString("User"));
                seminarPayment.setSeminarID(rs.getInt("SeminarID"));
                seminarPayment.setGroupPaymentID(rs.getInt("GroupPaymentID"));
                seminarPayment.setStatusPayment(rs.getBoolean("StatusPayment"));
                seminarPayment.setStatus(rs.getBoolean("Status"));
                seminarPayment.setDescription(rs.getString("Description"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            MyConnect.closeConntion(con, st, rs);
        }
        return seminarPayment;
    }

    public static PaymentSeminarEntities getPaymentSeminarBySeminarID(int seminarID) {
        PaymentSeminarEntities seminarPayment = new PaymentSeminarEntities();
        Connection con = null;
        Statement st = null;
        ResultSet rs = null;
        String sql = "Select * from PaymentSeminar where SeminarID=" + seminarID + " ";
        try {
            con = MyConnect.getConnection();
            st = con.createStatement();
            rs = st.executeQuery(sql);
            while (rs.next()) {
                seminarPayment.setID(rs.getInt("ID"));
                seminarPayment.setUser(rs.getString("User"));
                seminarPayment.setSeminarID(rs.getInt("SeminarID"));
                seminarPayment.setGroupPaymentID(rs.getInt("GroupPaymentID"));
                seminarPayment.setStatusPayment(rs.getBoolean("StatusPayment"));
                seminarPayment.setStatus(rs.getBoolean("Status"));
                seminarPayment.setDescription(rs.getString("Description"));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            MyConnect.closeConntion(con, st, rs);
        }
        return seminarPayment;
    }

    public static void main(String[] args) {
        PaymentSeminarEntities a = getPaymentSeminarByUserAndID("vinh", 1);
        System.out.println(a.getUser());
    }
}
